package main

import "fmt"

// 使用类型别名+可变参数
func main() {

	typeFiledTest()
	typeMethodTest()

	fmt.Printf("%d \n", sum00())
	fmt.Printf("%d \n", sum00(3, 4, 5, 6, 7, 4))
	fmt.Printf("%d \n", sum01(1))
	fmt.Printf("%d \n", sum01(1, 3, 4, 5, 6, 7, 4))

}

// typeFiledTest
//
//	@Description:  给数据类型设置别名
func typeFiledTest() {
	//给int取了一个别名，在go中  myInt和int都是int类型，但是认为是两个类

	type Integer int
	var num1 Integer = 10
	fmt.Printf("%T  %d\n", num1, num1)

	var num int = 10
	num = int(num1)
	fmt.Printf("%T  %d\n", num, num)

	type Float float32

	var num2 Float = 34.5
	fmt.Printf("%T  %f\n", num2, num2)

}

// Exchange 使用type

type Exchange func(n1 int, n2 int) (int, int)

func exchange(n1 int, n2 int) (int, int) {
	return n2, n1
}

func exchangeAsParam(method func(int, int) (int, int), n1 int, n2 int) (int, int) {
	return method(n1, n2)
}
func exchangeAsParam01(method Exchange, n1 int, n2 int) (int, int) {
	return method(n1, n2)
}

func typeMethodTest() {

	n2, n1 := exchangeAsParam(exchange, 101, 99)
	fmt.Println(n2, n1)

	n2, n1 = exchangeAsParam01(exchange, 101, 99)
	fmt.Println(n2, n1)
}

// 可变参数是slice切片,求一个到多个参数的和
func sum01(n1 int, nums ...int) int {
	var res int = n1
	for i := 0; i < len(nums); i++ {
		res += nums[i]
	}
	return res
}

// 可变参数是slice切片,求一个到多个参数的和
func sum00(nums ...int) int {
	var res int
	for i := 0; i < len(nums); i++ {
		res += nums[i]
	}
	return res
}
